﻿using System;
using System.Collections.Generic;
using Studio;
using UnityEngine;

// Token: 0x02000282 RID: 642
public class MapPlane : MonoBehaviour
{
	// Token: 0x060010AB RID: 4267 RVA: 0x0006A1A4 File Offset: 0x000683A4
	private void Awake()
	{
		Renderer[] componentsInChildren = base.gameObject.GetComponentsInChildren<Renderer>();
		foreach (Renderer rend in componentsInChildren)
		{
			this.dataList.Add(new MapPlane.Data(rend));
		}
	}

	// Token: 0x060010AC RID: 4268 RVA: 0x0006A1E8 File Offset: 0x000683E8
	private void Start()
	{
		this.camCtrl = Camera.main.GetComponent<CameraControl>();
		this.CalcPlane();
	}

	// Token: 0x060010AD RID: 4269 RVA: 0x0006A200 File Offset: 0x00068400
	private void LateUpdate()
	{
		if (ConfigData.autoHideObstacle && !this.plane.GetSide(this.camCtrl.transform.position) && this.plane.GetSide(this.camCtrl.targetObj.transform.position))
		{
			this.Hide();
		}
		else
		{
			this.Show();
		}
	}

	// Token: 0x060010AE RID: 4270 RVA: 0x0006A270 File Offset: 0x00068470
	private void OnDrawGizmosSelected()
	{
		float num = 2f;
		Quaternion quaternion = base.transform.rotation * Quaternion.Euler(this.planeRot);
		Vector3 vector = quaternion * Vector3.forward;
		Vector3 pos = base.transform.TransformPoint(this.planePos);
		Matrix4x4 rhs = Matrix4x4.TRS(Vector3.zero, quaternion, Vector3.one);
		Matrix4x4 lhs = Matrix4x4.TRS(pos, Quaternion.identity, Vector3.one);
		Gizmos.matrix = lhs * rhs;
		Gizmos.DrawCube(Vector3.zero, new Vector3(num, num, 0f));
		Gizmos.DrawLine(Vector3.zero, new Vector3(0f, 0f, num));
		Gizmos.matrix = Matrix4x4.identity;
	}

	// Token: 0x060010AF RID: 4271 RVA: 0x0006A32C File Offset: 0x0006852C
	private void OnValidate()
	{
		this.CalcPlane();
	}

	// Token: 0x060010B0 RID: 4272 RVA: 0x0006A334 File Offset: 0x00068534
	public void Show()
	{
		foreach (MapPlane.Data data in this.dataList)
		{
			data.Show();
		}
	}

	// Token: 0x060010B1 RID: 4273 RVA: 0x0006A390 File Offset: 0x00068590
	public void Hide()
	{
		foreach (MapPlane.Data data in this.dataList)
		{
			data.Hide(this.setLayer);
		}
	}

	// Token: 0x060010B2 RID: 4274 RVA: 0x0006A3F4 File Offset: 0x000685F4
	private void CalcPlane()
	{
		Quaternion rotation = base.transform.rotation * Quaternion.Euler(this.planeRot);
		Vector3 inNormal = rotation * Vector3.forward;
		Vector3 inPoint = base.transform.TransformPoint(this.planePos);
		this.plane = new Plane(inNormal, inPoint);
	}

	// Token: 0x040011D6 RID: 4566
	public Vector3 planePos;

	// Token: 0x040011D7 RID: 4567
	public Vector3 planeRot;

	// Token: 0x040011D8 RID: 4568
	public int setLayer = 16;

	// Token: 0x040011D9 RID: 4569
	private List<MapPlane.Data> dataList = new List<MapPlane.Data>();

	// Token: 0x040011DA RID: 4570
	private Plane plane;

	// Token: 0x040011DB RID: 4571
	private CameraControl camCtrl;

	// Token: 0x02000283 RID: 643
	private class Data
	{
		// Token: 0x060010B3 RID: 4275 RVA: 0x0006A448 File Offset: 0x00068648
		public Data(Renderer rend)
		{
			this.rend = rend;
			this.layer = rend.gameObject.layer;
		}

		// Token: 0x060010B4 RID: 4276 RVA: 0x0006A468 File Offset: 0x00068668
		public void Show()
		{
			this.rend.gameObject.layer = this.layer;
		}

		// Token: 0x060010B5 RID: 4277 RVA: 0x0006A480 File Offset: 0x00068680
		public void Hide(int setLayer)
		{
			this.rend.gameObject.layer = setLayer;
		}

		// Token: 0x040011DC RID: 4572
		private Renderer rend;

		// Token: 0x040011DD RID: 4573
		private int layer;
	}
}
